/*            Copyright(c) 2006-2008 Dave Sexton           *
 * http://www.codeplex.com/DocProject                      *
 * http://www.codeplex.com/DocProject/Project/License.aspx *
 ***********************************************************/
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using VSLangProj80;
using System.IO;

namespace DaveSexton.DocProject.Sandcastle
{
	public sealed partial class ChooseCompiledHelpControl : UserControl
	{
		#region Public Properties
		public bool ProduceHelpVersion1
		{
			get
			{
				return help1CheckBox.Checked;
			}
		}

		public bool ProduceHelpVersion2
		{
			get
			{
				return help2CheckBox.Checked;
			}
		}
		#endregion

		#region Private / Protected
		#endregion

		#region Constructors
		/// <summary>
		/// Constructs a new instance of the <see cref="ChooseCompiledHelpControl" /> class.
		/// </summary>
		public ChooseCompiledHelpControl()
		{
			InitializeComponent();

			infoLabel.Text = Resources.Text.ChooseCompiledHelpInfo;

			if (Help2CompilerStep.Help2APILoaded)
			{
				help2CheckBox.Enabled = true;
				help2Label.Text = Resources.Text.Help2xRequired;
				downloadHelp2xLink.Visible = false;
			}
			else
			{
				help2CheckBox.Enabled = false;
				help2Label.Text = Resources.Text.Help2xNotInstalled;
				downloadHelp2xLink.Visible = true;
			}
		}
		#endregion

		#region Methods
		public void SetDefaultValues(IDocProject project)
		{
			if (project == null)
			{
				help1CheckBox.Checked = false;
				help2CheckBox.Checked = false;
			}
			else
			{
				help1CheckBox.Checked = Help1xProject.IsEnabled(project);
				help2CheckBox.Checked = Help2xProject.IsEnabled(project);
			}
		}
		#endregion

		#region Event Handlers
		private void downloadHelp2xLink_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
		{
			if (VSEnvironmentHost.DefaultInstance.Version == "8.0")
				System.Diagnostics.Process.Start(Resources.Text.DownloadVisualStudioSDK2005);
			else
				System.Diagnostics.Process.Start(Resources.Text.DownloadVisualStudioSDK2008);
		}

		private void downloadHelp2xLink_MouseEnter(object sender, EventArgs e)
		{
			if (!DocProjectEnvironment.RunningInVisualStudio)
			{
				// NOTE: two calls are used to work-around a bug.
				// See https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=98281
				toolTip1.Show(Resources.Text.ExpressSDKWarning, downloadHelp2xLink, 0, downloadHelp2xLink.Height);
				toolTip1.Show(Resources.Text.ExpressSDKWarning, downloadHelp2xLink, 0, downloadHelp2xLink.Height);
			}
		}

		private void downloadHelp2xLink_MouseLeave(object sender, EventArgs e)
		{
			if (!DocProjectEnvironment.RunningInVisualStudio)
				toolTip1.Hide(downloadHelp2xLink);
		}
		#endregion
	}
}
